<template>
  <div class="pagination">
    <!-- <h1>{{ startNumAndEndNum }} ----当前页码数{{ pageNo }}</h1> -->
    <button>上一页</button>
    <button>1</button>
    <button>.....</button>

    <!-- 中间连续页码的地方:v-for、数组、对象、数字、字符串 -->
    <button>2</button>

    <button>......</button>
    <button>{{ totalPage }}</button>

    <button>下一页</button>

    <button style="margin-left:30px">共 {{ total }} 条</button>
  </div>
</template>

<script>
export default {
  name: 'Pagination',
  //   pageNo：当前第几个
  //   pageSize：代表每一页展示多少条数据
  //   total：代表整个分页展示多少条数据
  //   continues：代表分页器页码个数
  props: ["total", "pageSize", "pageNo", "pagerCount"],
  data() {
    return {
    };
  },
  computed: {
    // 总共多少页
    totalPage(){
      return Math.ceil(this.total/this.pageSize)
    },
    // 计算开始页数数 和 结束页数
    startNumAndEndNum(){
      let {continues,pageNo,totalPage} = this
      // 先定义两个变量存储 起始数字 和结束数字 
      let start =0,end = 0;
      // 连续页码数字【至少五页】，如果出现不正常【数据不够五页】
      if(continues > totalPage){
        start = 1
        end = totalPage
      }else{
        // 正常现象
        // 起始数字
        start = pageNo - parseInt(continues/2)
        // 结束数字
        end = pageNo + parseInt(continues/2)
        // start数字出现小于1 
        if(start < 1){
          start = 1
          end = continues
        }
        // 把不正常的现象【end数字大于页码数】
        if(end >totalPage){
          end = totalPage
          start = totalPage - continues + 1
        }
      }
      return {start,end}
    }

  },
  mounted() {

  },

  methods: {

  },
};
</script>

<style lang="less" scoped>
.pagination {
  button {
    margin: 0 5px;
    background-color: #f4f4f5;
    color: #606266;
    outline: none;
    border-radius: 2px;
    padding: 0 4px;
    vertical-align: top;
    display: inline-block;
    font-size: 13px;
    min-width: 35.5px;
    height: 28px;
    line-height: 28px;
    cursor: pointer;
    box-sizing: border-box;
    text-align: center;
    border: 0;

    &[disabled] {
      color: #c0c4cc;
      cursor: not-allowed;
    }

    &.active {
      cursor: not-allowed;
      background-color: #409eff;
      color: #fff;
    }
  }
}
</style>